import http from '@/utils/request'

const apiBefore = '/web/api-service'
const nTApiBefore = '/web/nt'
const wsApiBefore = '/web/wise'
const atApiBefore = '/web/autotask'

export const nextTicket = {
  getNextTicketOptions: (params, type) => {
    // if (params.type === 'autotask') {
    //   params.type = 'autotask'
    // }
    // if (!params.type) {
    //   params.type = 'nextTicket'
    // }
    return http.get(`${apiBefore}/ticket/filter/list`, { params })
    // if (type) return http.get(`${apiBefore}/ticket/filter/list?type=autotask`, { params })
    // else return http.get(`${apiBefore}/ticket/filter/list?type=nextTicket`, { params })
  },
  getNextTicketOptionsByUser: (params, type) => {
    return http.get(`${apiBefore}/ticket/filter/listFilterByUser`, { params })
  },
  getNextTicketCustomField: () => {
    return http.get(`${apiBefore}/customField/select?podId=85`)
  },
  // getNextTicketFilterByUser: (params, type) => {
  //   if (type) return http.get(`${apiBefore}/ticket/filter/listAuthFilterIdByUser?type=autotask`, { params })
  //   else return http.get(`${apiBefore}/ticket/filter/listAuthFilterIdByUser?type=nextTicket`, { params })
  // },
  saveNextTicketFilter: (params) => {
    return http.post(`${apiBefore}/ticket/filter`, params)
  },
  saveNextTicketFilterForUser: (params) => {
    return http.post(`${apiBefore}/ticket/filter/grantFilter`, params)
  },
  saveNextTicketTemplateForUser: (params) => {
    return http.post(`${apiBefore}/ticket/filter/grantModel`, params)
  },
  postNextTicketFilterGrant: (params) => {
    return http.post(`${apiBefore}/ticket/filter/grant`, params)
  },
  postAutoTaskTicket: (tenantCode, params) => {
    return http.post(`${atApiBefore}/tickets/${tenantCode}/syncTicket`, params)
  },
  postNTClickLog: (params) => {
    return http.post(`${apiBefore}/nextTicket/click/log`, params)
  },
  buildFilterStr: (params) => {
    return http.post(`${apiBefore}/ticket/filter/buildFilterStr`, params)
  },
  updateNextTicketFilter: (params) => {
    return http.put(`${apiBefore}/ticket/filter/${params.id}/update`, params)
  },
  updateFilterBatchApi: params => {
    return http.put(`${apiBefore}/ticket/filter/update/${params.pageId}`, params.filterList)
  },
  delNextTicketFilter: (params) => {
    return http.delete(`${apiBefore}/ticket/filter/${params.id}/delete`, { params })
  },
  getJiraFilterFields: () => {
    return http.get(`${apiBefore}/jira/base/filterFields`)
  },
  delNextTicketTemplate: (params, type) => {
    return http.delete(`${apiBefore}/rest/model/delete/${params.id}`, { params })
  },
  getTimeEntryDataListApi: params => {
    return http.get(`${apiBefore}/time-entry/list-sort`, { params })
  },
  getScheduleDataListApi: (params, type) => {
    if (type) return http.get(`${apiBefore}/schedule/by-identifier?identifier=${params.identifier}`)
    else return http.get(`${apiBefore}/schedule/by-identifier`, { params })
  },
  getNotesListApi: params => {
    return http.get(`${apiBefore}/rest/tickets/${params.clientCode}/notes/${params.ticketId}`)
  },
  getNextTicketUserListApi: params => {
    return http.get(`${apiBefore}/ticket/filter/listUsersFilterAuth?`, { params })
  },
  getBoardListApi: params => {
    return http.get(`${apiBefore}/boards/list`, { params })
  },
  getBoardStatusListApi: params => {
    return http.get(`${apiBefore}/board-status/list`, { params })
  },
  getRuleTemplateListApi: (params) => {
    return http.get(`${apiBefore}/rest/rules/template`, { params })
  },
  getTenantRuleListApi: (tenantCode, params) => {
    return http.get(`${apiBefore}/rest/rules/${tenantCode}`, { params })
  },
  getConnectWiseTicket: (tenantCode, ticketId) => {
    return http.get(`${wsApiBefore}/tickets/${tenantCode}/syncTicket?conditions=${ticketId}`)
  },
  deleteConnectWiseTicketApi: (ticketId) => {
    return http.delete(`${apiBefore}/cw/tickets?ticketIds=${ticketId}`)
  },
  getConnectWiseSchedules: (tenantCode, ticketId) => {
    return http.get(`${wsApiBefore}/schedules/${tenantCode}/sync?conditions=${ticketId}`)
  },
  updateTenantRuleApi: (tenantCode, params, type, templateName, modelId) => {
    if (modelId) {
      if (templateName) {
        return http.post(`${apiBefore}/rest/rules/${tenantCode}?type=${type}&modelName=${templateName}&modelId=${modelId}`, params)
      } else {
        return http.post(`${apiBefore}/rest/rules/${tenantCode}?type=${type}&modelId=${modelId}`, params)
      }
    } else {
      if (templateName) {
        return http.post(`${apiBefore}/rest/rules/${tenantCode}?type=${type}&modelName=${templateName}`, params)
      } else {
        return http.post(`${apiBefore}/rest/rules/${tenantCode}?type=${type}`, params)
      }
    }
  },
  getNextTicketDetail: params => {
    return http.get(`${apiBefore}/ticket/filter/detail`, { params })
  },
  getNextTicketTemplateList: params => {
    return http.get(`${apiBefore}/rest/model/list`, { params })
  },
  postSaveMaxRecordsNum: params => {
    return http.post(`${apiBefore}/sys/config/save`, params)
  },
  getMaxRecordsNum: (params) => {
    return http.get(`${apiBefore}/sys/config/selectConfig`, { params })
  },
  getNtGradingDataListAPI: params => {
    // conditions=id+%3D+389841
    return http.post(`${apiBefore}/rest/next-ticket/${params.clientCode}/grading`, params)
  },
  getSyncroGradingDataListAPI: (params, clientCode) => {
    return http.post(`${apiBefore}/rest/syncro/next-ticket/${clientCode}/grading`, params)
  },
  getkaseyabmsGradingDataListAPI: (params, clientCode) => {
    return http.post(`${apiBefore}/rest/kaseyabms/next-ticket/${clientCode}/grading`, params)
  },
  getGradingDataListAPI: (params, clientCode, type) => {
    return http.post(`${apiBefore}/rest/${type}/next-ticket/${clientCode}/grading`, params)
  },
  getAutoNtGradingDataListAPI: (params, clientCode) => {
    // conditions=id+%3D+389841
    return http.post(`${apiBefore}/rest/autotask/next-ticket/${clientCode.clientCode}/grading`, params)
  },
  getIdentifierUser: (params) => {
    return http.get(`${apiBefore}/users-identifiers/select`, { params })
  },
  getCompanyWatchRecord: (params) => {
    return http.get(`${apiBefore}/company-watch/record`, { params })
  },
  // getSelectCompanies: (params, type) => {
  //   if (type && type.origin_channel) return http.get(`${apiBefore}/cw/companies/selectCompanies?tenantCode=${params.tenantCode}&isAgreements=${params.isAgreements}&type=autotask`)
  //   else return http.get(`${apiBefore}/cw/companies/selectCompanies`, { params })
  // },
  addWatchListCompanies: (params, type) => {
    return http.post(`${apiBefore}/company-watch/insertBatch?type=${type}`, params)
  },
  delWatchListCompany: params => {
    return http.delete(`${apiBefore}/company-watch/remove/${params}`)
  },
  putAddCustomRuleApi: (params, type) => {
    return http.put(`${apiBefore}/rest/customRule/save?type=${type}`, params)
  },
  getCustomRuleListApi: (type,modelId) => {
    return http.get(`${apiBefore}/rest/customRule/list?type=${type}&modelId=${modelId}`)
  },
  deleteCustomRuleApi: (params,type) => {
    return http.delete(`${apiBefore}/rest/customRule/${params.id}?type=${type}`)
  },
}

export const apiService = {
  getDatasetErrorList: params => {
    return http.get(`${apiBefore}/schedule/dataset/refresh/error/page`, { params })
  },
  getReasonsOptionsList: (params, type) => {
    return http.get(`${apiBefore}/rest/reject/reason/${params}?type=${type}`)
  },
  getRejectTitcketList: (type) => {
    return http.get(`${apiBefore}/rest/reject/find?type=${type}`)
  },
  postRejectTicketData: params => {
    return http.post(`${apiBefore}/rest/reject/record`, params)
  },
  postRejectTicketRecovery: params => {
    return http.post(`${apiBefore}/rest/reject/recovery`, params)
  }

}

export const nextTicketDataInfo = {
  postNtGradingDataListAPI: params => {
    // conditions=id+%3D+389841
    return http.post(`${nTApiBefore}/next-ticket/${params.clientCode}/grading`, params)
  }
}
